package com.client;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;

public class Client {
    private static final String wsdlUrl = "http://127.0.0.1:9090/webService/testWebService?wsdl";
    private static final String operationName = "welcome";
    private static final Object[] params = new Object[]{"喵的还有谁....", "拿捏。。。"};

    public static void main(String[] args) {
        //创建动态客户端
        JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
        org.apache.cxf.endpoint.Client client = dcf.createClient(wsdlUrl);
        //添加发送请求拦截器
        client.getOutInterceptors().add(new ClientInterceptor("root", "123456"));
        try {
            Object[] response = client.invoke(operationName, params);
            System.out.println("返回数据:" + JSONObject.parse(JSON.toJSONString(response[0])));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}